package com.situ.water_BE.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.situ.water_BE.pojo.BeOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Mapper
@Resource
public interface BeOrderMapper extends BaseMapper<BeOrder> {
    @Select("select * from BE_Order where StepID=(\n" +
            "select id from BE_Flow where StepName=#{stepName}) ORDER BY CreateDate asc")
    public List<BeOrder> queryAll(String stepName);
    public int insert(BeOrder beOrder);
    @Select("select OrderNo from BE_Order ORDER BY CreateDate desc limit 1")
    public String orderNo();
    @Update("update be_order set StepID=#{stepID},AuditEmpID=#{auditEmpID},AuditMessage=#{text},LastEditEmp=#{lastEditEmp},LastEditDate=#{lastEditDate} where OrderNo=#{id}")
    public int updateStepID(String id,Integer auditEmpID,String text,Integer stepID, Integer lastEditEmp, Date lastEditDate);

    @Update("update be_order set StepID=#{stepID},LastEditEmp=#{lastEditEmp},LastEditDate=#{lastEditDate} where OrderNo=#{id}")
    public int updateStepID1(String id,Integer stepID, Integer lastEditEmp, Date lastEditDate);
    //交施工费日期
    @Update("update be_order set StepID=#{stepID},LastEditEmp=#{lastEditEmp},LastEditDate=#{lastEditDate},PayDate=#{lastEditDate} where OrderNo=#{id}")
    public int updateStepID2(String id,Integer stepID, Integer lastEditEmp, Date lastEditDate);

    public List<Map> gjQuery(BeOrder beOrder);

    public int gjQueryCount(BeOrder beOrder);

    @Select("SELECT o.orderNo,o.orderType,o.userName,o.address,o.linkMan,o.phone,f.stepName, e.empNmae,o.lastEditDate,o.payDate\n" +
            "FROM be_order o,be_flow f,sy_emp e\n" +
            "where o.StepID=f.id and e.id=o.LastEditEmp and o.StepID!=-1 and o.StepID!=0  and o.orderNo=#{id}")
    public Map queryId(String id);
    @Select("select UserNo from us_user ORDER BY CreateDate desc limit 1")
    public String queryAreaId(String orNo);
    @Select("select o.*,u.UserMoney from be_order o,us_user u where o.OldUserNo=u.UserNo and o.OrderNo=#{orderNo}")
    public Map queryIdUserAndOrder(String orderNo);

    public List<Map> queryBeOrderUserSQL(Map map);

    public int queryBeOrderUserSQLCount(Map map);
    @Select("select o.*,f.StepName from be_order o,be_flow f where f.id=o.StepID and StepID>0  order by CreateDate limit 7")
    public List<Map> limitBeOrderSQL();
}
